package com.hmy.security.service.impl;

import com.hmy.security.entity.User;
import com.hmy.security.mapper.UserMapper;
import com.hmy.security.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author hmy
 * @since 2023-01-30
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public User getUserByUid(Long uid) {
        if(uid <= 0) {
            throw new IllegalArgumentException("uid必须大于0");
        }
        return this.lambdaQuery()
                .eq(User::getUid, uid)
                .one();
    }

    @Override
    public User getUserByName(String name) {
        if (StringUtils.isBlank(name)) {
            throw new IllegalArgumentException("用户名不能为空");
        }
        return this.lambdaQuery()
                .eq(User::getUsername, name)
                .one();
    }
}
